use std::char::from_digit;

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let num_list: Vec<&str> = num_str.split(['(', ')']
        .as_ref())
        .filter(|it| !it.is_empty())
        .collect();
    let num = num_list[0];
    let in_base = num_list[1].parse().unwrap();
    if in_base < 2 || in_base > 16 {
        return String::from("Invalid to_base");
    }
    let num_radix = i64::from_str_radix(num, in_base).unwrap();
    let mut result = String::new();
    let mut value = num_radix;
    while value > 0 {
        let mod_num = (value % to_base as i64) as u8;
        result.push(from_digit(mod_num as u32, to_base).unwrap());
        value /= to_base as i64
    }
    result.chars().rev().collect()
}
